﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            double sum = 0;
            int n = 0;
            double term;
            int denominator = 1;
            int delta = 1;

            // 用于显示前10项
            string process = "";

            do
            {
                n++;
                term = 1.0 / denominator;
                sum += term;

                if (n <= 10)
                {
                    process += "1/" + denominator;
                    if (n < 10)
                        process += " + ";
                    else
                        process += " + ...";
                }

                denominator += delta;
                delta++;
            } while (term >= 1e-4); // 当项小于10^-4时停止

            txtProcess.Text = process;
            txtSum.Text = sum.ToString();
            txtN.Text = n.ToString();
        }
    }
}
